/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2023-12-27 11:33:35
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-06-26 15:44:00
 * @FilePath: \project\node-project\website-admin\src\utils\httpMethods.ts
 * @Description: 
 */
import request from './request'
import type { AxiosRequestConfig, AxiosResponse } from 'axios'

interface Http {
  get(url:string, data?:any, options?:AxiosRequestConfig):Promise<AxiosResponse>;
  post(url:string, data?:any, options?:AxiosRequestConfig):Promise<AxiosResponse>;
  put(url:string, data?:any, options?:AxiosRequestConfig):Promise<AxiosResponse>;
  deleted(url:string, data?:any, options?:AxiosRequestConfig):Promise<AxiosResponse>;
}


const httpMethods:Http = {
    get(url,data, options ) {
        return new Promise((reslove, reject) => {
            request.get(url, {params: data, ...options}).then(response => {
                reslove(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    post(url, data, options) {
        return new Promise((reslove, reject) => {
            request.post(url, data, {...options}).then(response => {
                reslove(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    put(url, data) {
        return new Promise((reslove, reject) => {
            request.put(url, data).then(response => {
                reslove(response)
            }).catch(error => {
                reject(error)
            })
        })
    },
    deleted(url, data, options)  {
        return new Promise((reslove, reject) => {
            request.delete(url, {data, ...options}).then(response => {
                reslove(response)
            }).catch(error => {
                reject(error)
            })
        })
    }
}

export default httpMethods